using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TangLiveRecorder
{
    public partial class Data
    {
        // 静态日志列表
        public static List<string> logs = new List<string>();

        // 日志添加事件
        public static event EventHandler<LogEventArgs> LogAdded;

        // 日志清空事件
        public static event EventHandler LogCleared;

        // 添加日志
        public static void AddLog(string message)
        {
            string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string logEntry = $"[{timestamp}] {message}";
            logs.Add(logEntry);

            // 限制日志数量
            if (logs.Count > 1000)
            {
                logs.RemoveRange(0, logs.Count - 800);
            }

            // 触发日志添加事件
            LogAdded?.Invoke(null, new LogEventArgs(logEntry));
        }

        // 清空日志
        public static void ClearLogs()
        {
            logs.Clear();
            LogCleared?.Invoke(null, EventArgs.Empty);
        }

        // 获取所有日志
        public static string GetAllLogs()
        {
            return string.Join(Environment.NewLine, logs);
        }

        // 日志事件参数类
        public class LogEventArgs : EventArgs
        {
            public string LogMessage { get; }

            public LogEventArgs(string logMessage)
            {
                LogMessage = logMessage;
            }
        }
    }
}